package com.ynny.UserManage.Controller;

import com.ynny.UserManage.Service.UserService;
import com.ynny.UserManage.enity.R;
import com.ynny.UserManage.enity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")

public class RegisterController {
    @Autowired
    private UserService userService;
    @PostMapping("/register")
    public R register(@RequestBody User user){
        System.out.println(user);
        if (user!=null){
            System.out.println(user);
            int register = userService.register(user);
            if (register==1){
                User user1 = userService.queryUserByName(user.getUsername());
                return R.ok(user1);
            }else if (register==-1){
                return R.error("用户已存在");
            }else if (register==-2) {
            return R.error("注册失败");
            }
        }return R.error("服务器异常");

    }


}
